package SJJGcode;

//  泛型练习

class MyArray<T>{
        public Object[] arr = new Object[3];

        public T getArr(int position){
            return (T)arr[position];
        };
        public void setArr(T value,int position){
            arr[position] = value;
        };
}

public class test1 {
    public static void main(String[] args) {
        // 实例化上面的数组对象  并指定其参数类型为Integer
        MyArray<Integer> myArray = new MyArray<>();
        myArray.setArr(49,1);
        Integer num = myArray.getArr(1);
        System.out.println("======================");
        //  实例化上面的数组对象   并指定参数类型为字符串
        MyArray<String> myArray1 = new MyArray<>();
        myArray1.setArr("c",0);
        String num1 = myArray1.getArr(0);
        System.out.println(num +" "+ num1);
    }
}
